<?php
namespace App\Library\SmsGateway;

class Adapter {
    const SUCCESS = 200;
    const SUCCESS_MESSAGE = '发送成功！';

    const ERROR = 500;
    const ERROR_MESSAGE = '发送失败，系统错误！';

    const ERROR_IP = 501;
    const ERROR_IP_MESSAGE = '发送失败，IP认证失败！';

    const ERROR_GATEWAY = 502;
    const ERROR_GATEWAY_MESSAGE = '发送失败，网关发送失败！';

    const ERROR_MT_EMPTY = 503;
    const ERROR_MT_EMPTY_MESSAGE = '发送失败，下发内容不能为空！';

    const ERROR_MT_LONG = 504;
    const ERROR_MT_LONG_MESSAGE = '发送失败，下发内容太长！';

    const ERROR_MOBILE = 505;
    const ERROR_MOBILE_MESSAGE = '发送失败，手机号码验证失败！';

    const ERROR_SEND_INTERVAL_TIME_ERROR = 506;
    const ERROR_SEND_INTERVAL_TIME_ERROR_MESSAGE = '发送失败，发送的间隔不能小于60秒！';

    const ERROR_SEND_HALF_HOUR_LIMIT_ERROR = 507;
    const ERROR_SEND_HALF_HOUR_LIMIT_ERROR_MESSAGE = '发送失败，半小时内只允许发送3条！';

    const ERROR_SEND_MAX = 508;
    const ERROR_SEND_MAX_MESSAGE = '发送失败，超过了每天最大的发送次数！';

    private $driver;

    public function loadDriver($driver) {
        $class = 'App\Library\SmsGateway\\' . ucfirst(strtolower($driver));

        $this->driver = new $class;
    }

    public function mt($mobile, $content) {
        return $this->driver->mt($mobile, $content);
    }

    public function mo($request) {
        return $this->driver->mo($request);
    }
}
